//
//  XLPersonPageUserInfoView.m
//  XiangLove
//
//  Created by 陈宪栋 on 2017/12/18.
//  Copyright © 2017年 BAOMIHUA.COM. All rights reserved.
//

#import "XLPersonPageUserInfoView.h"
#import <Masonry.h>

@implementation XLPersonPageUserInfoView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self setupView];
    }
    return self;
}

- (void)setupView {

    _coverImageView = [[UIImageView alloc] init];
    _coverImageView.contentMode = UIViewContentModeScaleAspectFill;
    _coverImageView.clipsToBounds = YES;
    [self addSubview:_coverImageView];
    [_coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    CAGradientLayer *bottomLayer = [[CAGradientLayer alloc] init];
    bottomLayer.colors = @[(id)RGBA(0, 0, 0, 0).CGColor, (id)RGBA(0, 0, 0, 0.5).CGColor];
    bottomLayer.locations = @[@(0), @(1)];
    bottomLayer.frame = CGRectMake(0, ScreenWidth / 375.0 * 400 - 115, ScreenWidth, 115);
    [self.layer addSublayer:bottomLayer];
    
    _chatCountLabel = [[UILabel alloc] init];
    _chatCountLabel.font = [UIFont systemFontOfSize:13];
    _chatCountLabel.textColor = [UIColor whiteColor];
    [self addSubview:_chatCountLabel];
    [_chatCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(15);
        make.bottom.equalTo(self.mas_bottom).offset(-12);
    }];
    
    _chatTimeLabel = [[UILabel alloc] init];
    _chatTimeLabel.font = [UIFont systemFontOfSize:13];
    _chatTimeLabel.textColor = [UIColor whiteColor];
    [self addSubview:_chatTimeLabel];
    [_chatTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_chatCountLabel.mas_right).offset(10);
        make.bottom.equalTo(self.mas_bottom).offset(-12);
    }];
    
    UIView *seprateLine = [[UIView alloc] init];
    seprateLine.backgroundColor = [UIColor whiteColor];
    [self addSubview:seprateLine];
    [seprateLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(15);
        make.right.equalTo(self.mas_right).offset(-15);
        make.bottom.equalTo(_chatTimeLabel.mas_top).offset(-12.5);
        make.height.mas_equalTo(1.0 / [UIScreen mainScreen].scale);
    }];
    
    _addressLabel = [[UILabel alloc] init];
    _addressLabel.font = [UIFont systemFontOfSize:12];
    _addressLabel.textColor = [UIColor whiteColor];
    [self addSubview:_addressLabel];
    [_addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(15);
        make.bottom.equalTo(_chatCountLabel.mas_top).offset(-25);
    }];
    
    _ageLabel = [[UILabel alloc] init];
    _ageLabel.font = [UIFont systemFontOfSize:12];
    _ageLabel.textColor = [UIColor whiteColor];
    [self addSubview:_ageLabel];
    [_ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_addressLabel.mas_right).offset(10);
        make.bottom.equalTo(_addressLabel.mas_bottom);
    }];
    
    _chatStatusLabel = [[UILabel alloc] init];
    _chatStatusLabel.layer.cornerRadius = 10;
    _chatStatusLabel.layer.masksToBounds = YES;
    _chatStatusLabel.textAlignment = NSTextAlignmentCenter;
    _chatStatusLabel.font = [UIFont systemFontOfSize:10];
    _chatStatusLabel.textColor = [UIColor whiteColor];
    [self addSubview:_chatStatusLabel];
    [_chatStatusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(50, 20));
        make.right.equalTo(self.mas_right).offset(-17);
        make.bottom.equalTo(_ageLabel.mas_bottom);
    }];
    
    _nickNameLabel = [[UILabel alloc] init];
    _nickNameLabel.font = [UIFont systemFontOfSize:30];
    _nickNameLabel.textColor = [UIColor whiteColor];
    [self addSubview:_nickNameLabel];
    [_nickNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(15);
        make.bottom.equalTo(_ageLabel.mas_top).offset(-1);
    }];
    
    _videoPlayButton = [[UIButton alloc] init];
    _videoPlayButton.hidden = YES;
    [_videoPlayButton setImage:[UIImage imageNamed:@"xl_play_icon"] forState:UIControlStateNormal];
    [self addSubview:_videoPlayButton];
    [_videoPlayButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    _indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    _indicatorView.hidden = YES;
    [self addSubview:_indicatorView];
    [_indicatorView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
}

- (void)showLoading {
    _indicatorView.hidden = NO;
    if ([_indicatorView isAnimating] == NO) {
        [_indicatorView startAnimating];
    }
}

- (void)hideLoading {
    _indicatorView.hidden = YES;
    if ([_indicatorView isAnimating]) {
        [_indicatorView stopAnimating];
    }
}

@end
